package com.ztgf.commodity.api.client;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.ztgf.commodity.models.bo.CommoditySpecificationBO;
import com.ztgf.commodity.models.dto.CommoditySpecificationDTO;
import com.ztgf.commodity.models.service.ICommoditySpecificationService;
import com.ztgf.common.constant.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * author: chenyu.wang
 * date: 2020-05-26 14:26
 * Description:商品规格
 */
@RestController
@RequestMapping("/api/commoditySpecification")
@Slf4j
@Api(value = "CommoditySpecificationApiController", tags = "商品规格表api接口")
public class CommoditySpecificationApiController {

    @DubboReference
    private ICommoditySpecificationService commoditySpecificationApiService;


//    @PostMapping(value = "/insert")
//    @ApiOperation(value = "添加商品规格表", notes = "添加商品规格表")
//    public Result insert(CommoditySpecificationSaveBO saveBO) {
//        boolean flag = commoditySpecificationApiService.add(saveBO);
//        if (flag) {
//            return new Result<>();
//        } else {
//            return new Result<>(CodeEnum.FAIL_100007);
//        }
//    }
//
//    @PostMapping("/update")
//    @ApiOperation(value = "修改商品规格表", notes = "修改商品规格表")
//    public Result update(CommoditySpecificationSaveBO saveBO) {
//        CommoditySpecificationDTO dto = new CommoditySpecificationDTO();
//        BeanUtils.copyProperties(saveBO, dto);
//        dto.setId(saveBO.getId());
//        boolean flag = commoditySpecificationApiService.updateById(dto);
//        if (flag) {
//            return new Result<>();
//        } else {
//            return new Result<>(CodeEnum.FAIL_100008);
//        }
//    }
//
//    @PostMapping("/deleteLogic")
//    @ApiOperation(value = "删除/恢复商品规格表(逻辑删除)", notes = "删除/恢复商品规格表(逻辑删除)")
//    @ApiImplicitParam(name = "id", value = "商品规格表id", required = true, paramType = "query", dataType = "Long")
//    public Result deleteLogic(Long id) {
//        if (id == null) {
//            return new Result<>(CodeEnum.FAIL_100002);
//        }
//        boolean flag = commoditySpecificationApiService.deleteLogic(id);
//        if (flag) {
//            return new Result<>();
//        } else {
//            return new Result<>(CodeEnum.FAIL_100009);
//        }
//    }

    @PostMapping("/queryPageList")
    @ApiOperation(value = "商品规格列表", notes = "商品规格列表")
    public Result<Page<CommoditySpecificationDTO>> queryPageList(CommoditySpecificationBO bo) {
        Wrapper<CommoditySpecificationDTO> wrapper = new EntityWrapper<>();
        if (bo.getName() != null) {
            wrapper.like("name", bo.getName());
        }
        wrapper.eq("is_publish", 1);
        wrapper.eq("status", 0);
        Page<CommoditySpecificationDTO> page = new Page<>(bo.getPageNo(), bo.getPageSize());
        page = commoditySpecificationApiService.selectPage(page, wrapper);
        return new Result<>(page);
    }


}
